<template>
  <div class="app-container">
    <loading v-show="loading"></loading>
    <el-card class="box-card searchFormStyle" style="margin-bottom:1%;">
      <div slot="header" class="clearfix">
        <span>试卷操作</span>
      </div>
      <div class="text item">
        <el-form ref="searchData" :model="searchData" label-width="130px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="试卷标题">
                <el-input v-model="searchData.name"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item>
                <el-button type="primary" 
                icon="el-icon-search"
                v-if="permissionHandle('testList:getList')"
                 @click="getList">查 询</el-button>
                 <el-button type="primary" 
                icon="el-icon-refresh"
                v-if="permissionHandle('testList:getList')"
                 @click="resetSearch">重 置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>试卷列表</span>
        </div>
        <el-table
          :data="tableData"
          border
          ref="tableData"
          style="width: 100%;margin-bottom:1%;"
          >
          <el-table-column
            label="试卷标题"
            width="180">
            <template slot-scope="scope">
                {{ scope.row.name }}
            </template>
          </el-table-column>
          <el-table-column
            label="卷面总分值"
            width="100"
          >
            <template slot-scope="scope">
                {{ scope.row.totalScore }}
            </template>
          </el-table-column>
          <el-table-column
            label="及格百分比"
            width="100">
            <template slot-scope="scope">
                {{ scope.row.passPercentage }}
            </template>
          </el-table-column>
          <el-table-column
            label="考试开始时间"
          >
            <template slot-scope="scope">
              <i class="el-icon-time"></i>
              <span style="margin-left: 10px">{{ scope.row.startTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="考试结束时间"
          >
            <template slot-scope="scope">
              <i class="el-icon-time"></i>
              <span style="margin-left: 10px">{{ scope.row.endTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            label="考试状态"
          >
            <template slot-scope="scope">
                {{ scope.row.status }}
            </template>
          </el-table-column>
          <el-table-column
            label="试题顺序"
            width="100">
            <template slot-scope="scope">
                {{ scope.row.questionOrder }}
            </template>
          </el-table-column>
          <el-table-column
            label="试卷描述"
            width="180">
            <template slot-scope="scope">
                {{ scope.row.description }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="130px">
            <template slot-scope="scope">
              <el-button
                size="mini"
                v-if="scope.row.pass === '未参加' && permissionHandle('testList:test')"
                icon="el-icon-edit-outline"
                @click="handleEdit(scope.$index, scope.row)">开始考试</el-button>
            </template>
          </el-table-column>
        </el-table>
      <pagination @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :paginations="paginations"></pagination>
    </el-card>
  </div>
</template>
<script>
import Loading from '@/components/loading/loading'
import pagination from '@/components/pagination/index'
import { getPaperList } from '@/api/examManagement/testList'

export default {
  components: {
    Loading,
    pagination
  },
  data() {
    this.permissionHandle = this.$permissionHandle
    return {
      paginations: {
        totalNum: 0,
        currentPage: 1,
        pageSize: 10
      },
      searchData: {
        name: '',
        pageSize: '10',
        pageNum: '1'
      },
      loading: false,
      tableData: [],
      testTypeLists: [],
      detailData: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetSearch() {
      this.searchData.name = ''
      this.getList()
    },
    blurSearch() {
      this.searchData.pageNum = 1
      this.getList()
      this.paginations.currentPage = 1
    },
    // 获取列表
    getList() {
      this.loading = true
      return new Promise((resolve, reject) => {
        getPaperList(this.searchData).then(response => {
          this.tableData = response.data.items
          this.paginations.totalNum = parseInt(response.data.itemsTotalCount)
          resolve()
          this.loading = false
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    // 改变分页的时候查询数据
    handleSizeChange(val) {
      this.SearchDep.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.SearchDep.pageNum = val
      this.getList()
    },
    handleEdit(index, row) {
      this.$router.push({
        path: 'testPage',
        name: '答题进行中',
        query: {
          infoId: row.id
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.upload-demo{display: inline-block;}
</style>
